package org.jeeasy.generate.domain;

import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.dromara.autotable.annotation.mysql.MysqlTypeConstant;
import org.dromara.mpe.annotation.InsertUpdateFillData;
import org.dromara.mpe.autotable.annotation.Column;
import org.dromara.mpe.autotable.annotation.Table;
import org.jeeasy.common.core.annotation.dict.Dict;
import org.jeeasy.common.core.base.BaseEntity;
import org.jeeasy.common.core.enums.BooleanEnum;
import org.jeeasy.common.core.handler.SysOrgCodeAutoFillHandler;
import org.jeeasy.generate.emuns.RelationTypeEnum;
import org.jeeasy.generate.emuns.TableStyleEnum;
import org.jeeasy.generate.emuns.TableTypeEnum;

import java.util.List;

/**
 * 代码生成 模块
 *
 * @author wei.yang
 * @date 2023-12-14
 */
@Data
@Table(value = "gen_table", comment = "表配置")
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class GenTable extends BaseEntity<GenTable> {

    /**
     * 表名
     */
    @Column(comment = "表名", length = 36)
    private String name;

    /**
     * 表描述
     */
    @Column(comment = "表摘要", length = 64)
    private String summary;

    /**
     * 表描述
     */
    @Column(comment = "表描述", length = 64)
    private String description;

    /**
     * 数据源
     */
    @Column(comment = "数据源", length = 36)
    private String dataSource;

    /**
     * 同步数据库状态
     */
    @Column(comment = "同步数据库状态", length = 1, type = MysqlTypeConstant.TINYINT)
    @Dict(dictEnum = BooleanEnum.class)
    private Integer izSync = 0;

    /**
     * 是否简单查询
     */
    @Column(comment = "是否简单查询", length = 1, type = MysqlTypeConstant.TINYINT)
    @Dict(dictEnum = BooleanEnum.class)
    private Integer izSimpleQuery = 1;

    /**
     * 是否分页
     */
    @Column(comment = "是否分页", length = 1, type = MysqlTypeConstant.TINYINT)
    @Dict(dictEnum = BooleanEnum.class)
    private Integer izPage = 1;

    /**
     * 是否是树
     */
    @Column(comment = "是否是树", length = 1, type = MysqlTypeConstant.TINYINT)
    @Dict(dictEnum = BooleanEnum.class)
    private Integer izTree = 0;

    /**
     * 树PID
     */
    @Column(comment = "树PID", length = 24)
    private String treePid = "pid";

    /**
     * 树名称字段
     */
    @Column(comment = "树名称字段", length = 36)
    private String treeNameField = "name";

    /**
     * 表单风格
     */
    @Column(comment = "表单风格", length = 2)
    @Dict(dictEnum = TableStyleEnum.class)
    private Integer formType = 12;

//    /**
//     * 主键生成序列
//     */
//    @Column(comment = "主键生成序列")
//    private String idSequence;

//    /**
//     * 主键类型
//     */
//    @Column(comment = "主键类型")
//    @Dict(dictEnum = IdTypeEnum.class)
//    private Integer idType = 3;

    /**
     * 表类型
     * single单表、main主表、slave附表、catalog分类
     */
    @Column(comment = "表类型", length = 10)
    @Dict(dictEnum = TableTypeEnum.class)
    private String tableType = "single";

    /**
     * 主表
     */
    @Column(comment = "主表", length = 36)
    private String mainTable = "";

    /**
     * 从表
     */
    @Column(comment = "从表", length = 255)
    private String slaveTable = "";

    ///**
    // * 主表字段
    // */
    //@Column(comment = "主表字段", length = 36)
    //@com.baomidou.mybatisplus.annotation.TableField(exist = false)
    //private String mainColumn = "";
    //
    ///**
    // * 主表字段Code
    // */
    //@Column(comment = "主表字段Code", length = 36)
    //@com.baomidou.mybatisplus.annotation.TableField(exist = false)
    //private String mainColumnCode = "";
    //
    ///**
    // * 从表字段
    // */
    //@Column(comment = "从表字段", length = 36)
    //@com.baomidou.mybatisplus.annotation.TableField(exist = false)
    //private String slaveColumn = "";
    //
    ///**
    // * 从表字段Code
    // */
    //@Column(comment = "从表字段Code")
    //@com.baomidou.mybatisplus.annotation.TableField(exist = false)
    //private String slaveColumnCode = "";

    /**
     * 映射关系
     */
    @Column(comment = "映射关系", length = 20)
    @Dict(dictEnum = RelationTypeEnum.class)
    private String relationType = "oneToMany";

    /**
     * 子表
     */
    @Column(comment = "子表", length = 36)
    private String subTableStr;

    /**
     * 附表排序序号
     */
    @Column(comment = "附表排序序号", length = 4, decimalLength = 2)
    private Double tabOrderNum = 1.0;

    /**
     * 所属部门
     */
    @Column(comment = "所属部门", length = 255)
    @InsertUpdateFillData(SysOrgCodeAutoFillHandler.class)
    //@TableField(fill = FieldFill.INSERT)
    private String sysOrgCode;

    //@Column(comment = "字段列表")
    @TableField(exist = false)
    private List<GenTableField> tableFields;

    //@Column(comment = "索引列表")
    @TableField(exist = false)
    private List<GenTableIndex> tableIndexes;
}
